// subPages/bodyTrend/bodyTrend.js
import * as echarts from '../../../ec-canvas/echarts';
var jsonData = require('../../../data/bodyTrendJson');
var jsonData2 = require('../../../data/bodyTrendJson2');
var navListJson = require('../../../data/navListJson');
var util =  require('../../../utils/util.js');
var template = require('../../../template/template.js');
let Chart = null;
let LineChart = null
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,//当前页面
    navScrollLeft: 0,
    ec: {
      // lazyLoad: true // 延迟加载
    },
    ec2: {
      // lazyLoad: true // 延迟加载
    },
    tabBarShow: true,
    type: 'bar'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      navList: navListJson.bodyTrendNavList
    })
    wx.getSystemInfo({
      success: (res) => {
        //创建节点选择器
        that.setData({
          windowWidth: res.windowWidth
        })
      },
    })
    if(options.item != null && options.item != 'undefined'){
      var item =  JSON.parse(options.item)
      that.setData({
        tabBarShow: false
      })
      wx.setNavigationBarTitle({
        title: item.nickName + '的体趋势' //页面标题为路由参数
      })
      that.getTrendData(item.userId)
    }else{
      template.bodyFatTabbar("tabBar", 1, this) //0表示第一个tabbar
      that.getTrendData()
    }
    that.barchartsComponnet = that.selectComponent('#mychart');
    that.linechartsComponnet = that.selectComponent('#mychartLine');
  },

  //获得数据
  getTrendData:function(userId){
    var that = this
    var id = ''
    if(userId != '' && userId != 'undefined' && userId != null){
      id = userId
    }else{
      id = app.globalData.userId
    }
    wx.request({
        url: app.globalData.apiUrl +'/getqx',
        data: {
          id: id,
        },
        method: 'get',
        header: {
          'content-type': 'application/json' //默认值
        },
        success: function (res) {
          // console.log(res)
          if(res.data.code == '200'){
            that.processingData(res);
            that.processingEchartData(res);
            if(res.data.msg != 0){
              that.getBarGraphData(that.data.weightData,that.data.weightTime);  //创建图表
              
            }
            that.setData({
              msg : res.data.msg
            })
          }else{
            util.showModal('提示','数据异常')
            return;
          }
        },
        fail: function (res) {
          console.log("失败",res);
        }
    })
  },

  //处理图表数据
  processingEchartData:function(res){
    var that = this
    if(res.data.msg != 0){
      //体重
      var weightData = [];
      var weightTime = []
      for(var i=0;i<res.data.data.weight.list.length;i++)
      {
        weightData.push(res.data.data.weight.list[i].value)
        var time = util.setTime(res.data.data.weight.list[i].time.substring(0,10))
        weightTime.push(time)
      }
      that.setData({
        weightData: weightData,
        weightTime: weightTime
      })

      //初始化默认显示
      if(this.data.currentTab == 0)
      {
        that.setData({
          recordData: weightData[0],
          recordTitle:'体重',
          recordTime: weightTime[0]
        })
      }

      //bmi
      var bmiData = [];
      var bmiTime = []
      for(var i=0;i<res.data.data.bmi.list.length;i++)
      {
        bmiData.push(res.data.data.bmi.list[i].value)
        var time = util.setTime(res.data.data.bmi.list[i].time.substring(0,10))
        bmiTime.push(time)
      }
      that.setData({
        bmiData: bmiData,
        bmiTime: bmiTime
      })

      //脂肪
      var bodyFatData = [];
      var bodyFatTime = []
      for(var i=0;i<res.data.data.bodyFat.list.length;i++)
      {
        bodyFatData.push(res.data.data.bodyFat.list[i].value)
        var time = util.setTime(res.data.data.bodyFat.list[i].time.substring(0,10))
        bodyFatTime.push(time)
      }
      that.setData({
        bodyFatData: bodyFatData,
        bodyFatTime: bodyFatTime
      })

      //肌肉量
      var muscleMassData = [];
      var muscleMassTime = []
      for(var i=0;i<res.data.data.muscleMass.list.length;i++)
      {
        muscleMassData.push(res.data.data.muscleMass.list[i].value)
        var time = util.setTime(res.data.data.muscleMass.list[i].time.substring(0,10))
        muscleMassTime.push(time)
      }
      that.setData({
        muscleMassData: muscleMassData,
        muscleMassTime: muscleMassTime
      })

      //水分率
      var waterContentData = [];
      var waterContentTime = []
      for(var i=0;i<res.data.data.waterContent.list.length;i++)
      {
        waterContentData.push(res.data.data.waterContent.list[i].value)
        var time = util.setTime(res.data.data.waterContent.list[i].time.substring(0,10))
        waterContentTime.push(time)
      }
      that.setData({
        waterContentData: waterContentData,
        waterContentTime: waterContentTime
      })

      //骨量
      var skeletonContentData = [];
      var skeletonContentTime = []
      for(var i=0;i<res.data.data.skeletonContent.list.length;i++)
      {
        skeletonContentData.push(res.data.data.skeletonContent.list[i].value)
        var time = util.setTime(res.data.data.skeletonContent.list[i].time.substring(0,10))
        skeletonContentTime.push(time)
      }
      that.setData({
        skeletonContentData: skeletonContentData,
        skeletonContentTime: skeletonContentTime
      })

      //内脏脂肪
      var visceralFatRateData = [];
      var visceralFatRateTime = []
      for(var i=0;i<res.data.data.visceralFatRate.list.length;i++)
      {
        visceralFatRateData.push(res.data.data.visceralFatRate.list[i].value)
        var time = util.setTime(res.data.data.visceralFatRate.list[i].time.substring(0,10))
        visceralFatRateTime.push(time)
      }
      that.setData({
        visceralFatRateData: visceralFatRateData,
        visceralFatRateTime: visceralFatRateTime
      })

      //基础代谢
      var bmrData = [];
      var bmrTime = []
      for(var i=0;i<res.data.data.bmr.list.length;i++)
      {
        bmrData.push(res.data.data.bmr.list[i].value)
        var time = util.setTime(res.data.data.bmr.list[i].time.substring(0,10))
        bmrTime.push(time)
      }
      that.setData({
        bmrData: bmrData,
        bmrTime: bmrTime
      })

      //蛋白质率
      var proteinData = [];
      var proteinTime = []
      for(var i=0;i<res.data.data.protein.list.length;i++)
      {
        proteinData.push(res.data.data.protein.list[i].value)
        var time = util.setTime(res.data.data.protein.list[i].time.substring(0,10))
        proteinTime.push(time)
      }
      that.setData({
        proteinData: proteinData,
        proteinTime: proteinTime
      })
    }
  },

  //处理数据
  processingData:function(res){
    var that = this
    if(res.data.msg != 0){
      //体重
      var weightList = jsonData.weightList
      for(var i=0; i<weightList.length; i++)
      {
        if(weightList[i].text == '累计记录天数'){
          weightList[i].data = res.data.msg;
        }
        else if(weightList[i].text.substring(0,2) == '最高'){
          weightList[i].data = res.data.data.weight.max;
        }
        else if(weightList[i].text.substring(0,2) == '最低'){
          if(res.data.data.weight.min != 0)
          {
            weightList[i].data = res.data.data.weight.min;
          }
        }
        else {
          if(res.data.data.weight.min != 0){
            weightList[i].data = ((res.data.data.weight.max - res.data.data.weight.min) / res.data.data.weight.min).toFixed(2);
          }
        }
      }

      //bmi
      var bmiList = jsonData.bmiList
      for(var i=0; i<bmiList.length; i++)
      {
        if(bmiList[i].text == '累计记录天数'){
          bmiList[i].data = res.data.msg;
        }
        else if(bmiList[i].text.substring(0,2) == '最高'){
          bmiList[i].data = res.data.data.bmi.max;
        }
        else if(bmiList[i].text.substring(0,2) == '最低'){
          if(res.data.data.bmi.min != 0){
            bmiList[i].data = res.data.data.bmi.min;
          }
        }
        else {
          if(res.data.data.bmi.min != 0){
            bmiList[i].data = ((res.data.data.bmi.max - res.data.data.bmi.min) / res.data.data.bmi.min).toFixed(2);
          }
        }
      }

      //脂肪
      var bodyFatList = jsonData.bodyFatList
      for(var i=0; i<bodyFatList.length; i++)
      {
        if(bodyFatList[i].text == '累计记录天数'){
          bodyFatList[i].data = res.data.msg;
        }
        else if(bodyFatList[i].text.substring(0,2) == '最高'){
          bodyFatList[i].data = res.data.data.bodyFat.max;
        }
        else if(bodyFatList[i].text.substring(0,2) == '最低'){
          if(res.data.data.bodyFat.min != 0)
          {
            bodyFatList[i].data = res.data.data.bodyFat.min;
          }
        }
        else {
          if(res.data.data.bodyFat.min != 0)
          {
            bodyFatList[i].data = ((res.data.data.bodyFat.max - res.data.data.bodyFat.min) / res.data.data.bodyFat.min).toFixed(2);
          }
        }
      }
      

      //肌肉量
      var muscleMassList = jsonData.muscleMassList
      for(var i=0; i<muscleMassList.length; i++)
      {
        if(muscleMassList[i].text == '累计记录天数'){
          muscleMassList[i].data = res.data.msg;
        }
        else if(muscleMassList[i].text.substring(0,2) == '最高'){
          muscleMassList[i].data = res.data.data.muscleMass.max;
        }
        else if(muscleMassList[i].text.substring(0,2) == '最低'){
          if(res.data.data.muscleMass.min != 0){
            muscleMassList[i].data = res.data.data.muscleMass.min;
          }
        }
        else {
          if(res.data.data.muscleMass.min != 0){
            muscleMassList[i].data = ((res.data.data.muscleMass.max - res.data.data.muscleMass.min) / res.data.data.muscleMass.min).toFixed(2);
          }
        }
      }

      //水分
      var waterContentList = jsonData.waterContentList
      for(var i=0; i<waterContentList.length; i++)
      {
        if(waterContentList[i].text == '累计记录天数'){
          waterContentList[i].data = res.data.msg;
        }
        else if(waterContentList[i].text.substring(0,2) == '最高'){
          waterContentList[i].data = res.data.data.waterContent.max;
        }
        else if(waterContentList[i].text.substring(0,2) == '最低'){
          if(res.data.data.waterContent.min != 0){
            waterContentList[i].data = res.data.data.waterContent.min;
          }
        }
        else {
          if(res.data.data.waterContent.min != 0){
            waterContentList[i].data = ((res.data.data.waterContent.max - res.data.data.waterContent.min) / res.data.data.waterContent.min).toFixed(2);
          }
        }
      }

      //骨量
      var skeletonContentList = jsonData.skeletonContentList
      for(var i=0; i<skeletonContentList.length; i++)
      {
        if(skeletonContentList[i].text == '累计记录天数'){
          skeletonContentList[i].data = res.data.msg;
        }
        else if(skeletonContentList[i].text.substring(0,2) == '最高'){
          skeletonContentList[i].data = res.data.data.skeletonContent.max;
        }
        else if(skeletonContentList[i].text.substring(0,2) == '最低'){
          if(res.data.data.skeletonContent.min != 0){
            skeletonContentList[i].data = res.data.data.skeletonContent.min;
          }
        }
        else {
          if(res.data.data.skeletonContent.min != 0){
            skeletonContentList[i].data = ((res.data.data.skeletonContent.max - res.data.data.skeletonContent.min) / res.data.data.skeletonContent.min).toFixed(2);
          }
        }
      }

      //内脏脂肪
      var visceralFatRateList = jsonData.visceralFatRateList
      for(var i=0; i<visceralFatRateList.length; i++)
      {
        if(visceralFatRateList[i].text == '累计记录天数'){
          visceralFatRateList[i].data = res.data.msg;
        }
        else if(visceralFatRateList[i].text.substring(0,2) == '最高'){
          visceralFatRateList[i].data = res.data.data.visceralFatRate.max;
        }
        else if(visceralFatRateList[i].text.substring(0,2) == '最低'){
          if(res.data.data.visceralFatRate.min != 0){
            visceralFatRateList[i].data = res.data.data.visceralFatRate.min;
          }
        }
        else {
          if(res.data.data.visceralFatRate.min != 0){
            visceralFatRateList[i].data = ((res.data.data.visceralFatRate.max - res.data.data.visceralFatRate.min) / res.data.data.visceralFatRate.min).toFixed(2);
          }
        }
      }

      //基础代谢
      var bmrList = jsonData.bmrList
      for(var i=0; i<bmrList.length; i++)
      {
        if(bmrList[i].text == '累计记录天数'){
          bmrList[i].data = res.data.msg;
        }
        else if(bmrList[i].text.substring(0,2) == '最高'){
          bmrList[i].data = res.data.data.bmr.max;
        }
        else if(bmrList[i].text.substring(0,2) == '最低'){
          if(res.data.data.bmr.min != 0){
            bmrList[i].data = res.data.data.bmr.min;
          }
        }
        else {
          if(res.data.data.bmr.min != 0){
            bmrList[i].data = ((res.data.data.bmr.max - res.data.data.bmr.min) / res.data.data.bmr.min).toFixed(2);
          }
        }
      }

      //蛋白质
      var proteinList = jsonData.proteinList
      for(var i=0; i<bmrList.length; i++)
      {
        if(proteinList[i].text == '累计记录天数'){
          proteinList[i].data = res.data.msg;
        }
        else if(proteinList[i].text.substring(0,2) == '最高'){
          if(res.data.data.protein.min != 0 && res.data.data.protein.min != null){
            proteinList[i].data = res.data.data.protein.max;
          }
        }
        else if(proteinList[i].text.substring(0,2) == '最低'){
          if(res.data.data.protein.min != 0 && res.data.data.protein.min != null){
            proteinList[i].data = res.data.data.protein.min;
          }
        }
        else {
          if(res.data.data.protein.min != 0  && res.data.data.protein.min != null){
            proteinList[i].data = ((res.data.data.protein.max - res.data.data.protein.min) / res.data.data.protein.min).toFixed(2);
          }
        }
      }
      that.setData({
        weightList:weightList,
        bmiList:bmiList,
        muscleMassList:muscleMassList,
        bodyFatList:bodyFatList,
        waterContentList: waterContentList,
        skeletonContentList: skeletonContentList,
        visceralFatRateList: visceralFatRateList,
        bmrList: bmrList,
        proteinList: proteinList
      })
    }
    else{
      that.setData({
        weightList: jsonData2.weightList,
        bmiList: jsonData2.bmiList,
        muscleMassList: jsonData2.muscleMassList,
        bodyFatList: jsonData2.bodyFatList,
        waterContentList: jsonData2.waterContentList,
        skeletonContentList: jsonData2.skeletonContentList,
        visceralFatRateList: jsonData2.visceralFatRateList,
        bmrList: jsonData2.bmrList,
        proteinList: jsonData2.proteinList
      })
    }
  },

  //选择图表
  gBtn:function(e){
    var that = this
    var type = e.currentTarget.dataset.type
    that.setData({
      type: type
    })
    LineChart = null
    if(type == 'line'){
      switch (that.data.currentTab) {
        case 0:
          that.getLineGraphData(that.data.weightData,that.data.weightTime)
          break;
        case 1:
          that.getLineGraphData(that.data.bmiData,that.data.bmiTime)
          break;
        case 2:
          that.getLineGraphData(that.data.bodyFatData,that.data.bodyFatTime)
          break;
        case 3:
          that.getLineGraphData(that.data.muscleMassData,that.data.muscleMassTime)
          break;
        case 4:
          that.getLineGraphData(that.data.waterContentData,that.data.waterContentTime)
          break;
        case 5:
          that.getLineGraphData(that.data.skeletonContentData,that.data.skeletonContentTime)
          break;
        case 6:
          that.getLineGraphData(that.data.visceralFatRateData,that.data.visceralFatRateTime)
          break;
        case 7:
          that.getLineGraphData(that.data.bmrData,that.data.bmrTime)
          break;
        case 8:
          that.getLineGraphData(that.data.proteinData,that.data.proteinTime)
          break;
      }
    }
  },

  //柱状图表
  getBarGraphData:function(data,time){
    if(data == null || time == null) return;
    var that = this
    if (!Chart){
      that.init_barEcharts(data,time); //初始化图表
    }else{
      that.setBarOption(data,time); //更新数据
    }
  },

  //初始化图表
  init_barEcharts: function (data,time) {
    var that = this
    that.barchartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      Chart = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      Chart.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setBarOption(this.getBarOption());
      that.setBarOption(data,time);
      Chart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: 0
      });
      Chart.on('click',{seriesIndex: 0},function(e){
        that.setData({
          recordTime: e.name,
          recordData: e.data
        })
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return Chart;
    });
  },

  setBarOption: function (data,time) {
    Chart.clear();  // 清除
    Chart.setOption(this.getBarOption(data,time));  //获取新数据
  },

  //设置柱状图表
  getBarOption: function (data,time) {
    var end = (8 / data.length) * 100
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:0,
        x2:30,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:false,
        boundaryGap:false,
        data : time,
      },
      yAxis: {
        type: 'value',
        boundaryGap:false,
        show:false,
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: 0,
          end: end,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'',
        type:'bar',
        barCategoryGap: '40%',
        barMaxWidth: 40,
        itemStyle : {
          normal: {
            color: 'rgba(255,255,255,0.5)',
            barBorderRadius: [25, 25, 0, 0],
            label : {
              show: true,
              color: '#000',
              position: 'bottom',
              formatter:function(params){
                let time = util.setTime6(params.name)
                return time;
              }
            }
          },
          emphasis:{
            color: '#fff',
            barBorderRadius: [25, 25, 0, 0],
            label : {
              show: true,
              color: '#000',
              textStyle:{
                fontSize:12
              }
            }
          }
        },
        data:data
      }]
    };
    Chart.hideLoading()
    return option;
  },


  //线图表
  getLineGraphData:function(data,time){
    if(data == null || time == null) return;
    var that = this
    if (!LineChart){
      that.init_LineEcharts(data,time); //初始化图表
    }else{
      that.setLineOption(data,time); //更新数据
    }
  },

  //初始化图表
  init_LineEcharts: function (data,time) {
    var that = this
    that.linechartsComponnet.init((canvas, width, height) => {
      // 初始化图表
      LineChart = echarts.init(canvas, null, {
        width: width,
        height: height
      });
      LineChart.showLoading({
        text : '正在努力的读取数据中...'
      });
      // Chart.setLineOption(this.getLineOption());
      that.setLineOption(data,time);
      LineChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: 0
      });
      LineChart.on('click',{seriesIndex: 0},function(e){
        that.setData({
          recordTime: e.name,
          recordData: e.data
        })
      })
      // 注意这里一定要返回 chart 实例，否则会影响事件处理等
      return LineChart;
    });
  },

  setLineOption: function (data,time) {
    LineChart.clear();  // 清除
    LineChart.setOption(this.getLineOption(data,time));  //获取新数据
  },

  //设置折线图表
  getLineOption: function (data,time) {
    var end = (8 / data.length) * 100
    // 指定图表的配置项和数据
    var option = {
      title : {
        text: '',
        subtext: ''
      },
      grid:{ 
        borderWidth:0,
        x:0,
        y:10,
        x2:30,
        y2:0,
        containLabel: true
      },
      xAxis: { 
        type: 'category',
        show:true,
        boundaryGap:false,
        data : time,
        axisLine:{
          show:false
        },
        axisTick:{
            show:false
        },
        axisLabel:{
            show:true,
            interval: 0,
            formatter: '{value}',
            formatter:function(value){
              return util.setTime6(value)
            }
        },
      },
      yAxis: {
        type: 'value',
        boundaryGap:false,
        show:false,
      },
      dataZoom:[
        {
          show: false,
          type:'slider',
          start: 0,
          end: end,
          left:'3%',
          right:'3%',
          maxValueSpan: 10,
        },
        {
          type: 'inside',
        },
      ],
      series : [{
        name:'',
        type:'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 10,
        itemStyle : {
          normal: {
            color: '#fff',
          },
        },
        emphasis:{
          itemStyle:{
              borderWidth: 10,
              borderType:'solid',
              borderColor: 'rgba(246,246,246,0.5)'
          }
        },
        data:data
      }]
    };
    LineChart.hideLoading()
    return option;
  },

  //选择导航栏
  switchNav(event){
    var cur = event.currentTarget.dataset.current; 
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 5;
    //tab选项居中                            
    this.setData({
        navScrollLeft: (cur - 2) * singleNavWidth
    })      
    if (this.data.currentTab == cur) {
        return false;
    } else {
        this.setData({
            currentTab: cur
        })
    }
    // this.setEchartsData(cur)
  },

  //内容滚动
  switchTab(event){
    var that = this
    var cur = event.detail.current;
    var singleNavWidth = that.data.windowWidth / 5;
    this.setData({
        currentTab: cur,
        navScrollLeft: (cur - 2) * singleNavWidth
    });
    if(that.data.msg != 0){
      that.setEchartsData(cur)
    }
  }, 

  //给图表赋值
  setEchartsData:function(cur){
    var that = this
    switch (cur) {
      case 0:
        //体重
        that.getBarGraphData(that.data.weightData,that.data.weightTime)
        that.getLineGraphData(that.data.weightData,that.data.weightTime)
        that.setData({
          recordData: that.data.weightData[0],
          recordTime: that.data.weightTime[0],
          recordTitle: '体重'
        })
        break;
      case 1:
        //bmi
        that.getBarGraphData(that.data.bmiData,that.data.bmiTime)
        that.getLineGraphData(that.data.bmiData,that.data.bmiTime)
        that.setData({
          recordData: that.data.bmiData[0],
          recordTime: that.data.bmiTime[0],
          recordTitle: 'bmi'
        })
        break;
      case 2:
        //脂肪
        that.getBarGraphData(that.data.bodyFatData,that.data.bodyFatTime)
        that.getLineGraphData(that.data.bodyFatData,that.data.bodyFatTime)
        that.setData({
          recordData: that.data.bodyFatData[0],
          recordTime: that.data.bodyFatTime[0],
          recordTitle: '脂肪'
        })
        break;
      case 3:
        //肌肉量
        that.getBarGraphData(that.data.muscleMassData,that.data.muscleMassTime)
        that.getLineGraphData(that.data.muscleMassData,that.data.muscleMassTime)
        that.setData({
          recordData: that.data.muscleMassData[0],
          recordTime: that.data.muscleMassTime[0],
          recordTitle: '肌肉量'
        })
        break;
      case 4:
        //水分率
        that.getBarGraphData(that.data.waterContentData,that.data.waterContentTime)
        that.getLineGraphData(that.data.waterContentData,that.data.waterContentTime)
        that.setData({
          recordData: that.data.waterContentData[0],
          recordTime: that.data.waterContentTime[0],
          recordTitle: '水分率'
        })
        break;
      case 5:
        //骨量
        that.getBarGraphData(that.data.skeletonContentData,that.data.skeletonContentTime)
        that.getLineGraphData(that.data.skeletonContentData,that.data.skeletonContentTime)
        that.setData({
          recordData: that.data.skeletonContentData[0],
          recordTime: that.data.skeletonContentTime[0],
          recordTitle: '骨量'
        })
        break;
      case 6:
        //内脏脂肪
        that.getBarGraphData(that.data.visceralFatRateData,that.data.visceralFatRateTime)
        that.getLineGraphData(that.data.visceralFatRateData,that.data.visceralFatRateTime)
        that.setData({
          recordData: that.data.visceralFatRateData[0],
          recordTime: that.data.visceralFatRateTime[0],
          recordTitle: '内脏脂肪'
        })
        break;
      case 7:
        //基础代谢
        that.getBarGraphData(that.data.bmrData,that.data.bmrTime)
        that.getLineGraphData(that.data.bmrData,that.data.bmrTime)
        that.setData({
          recordData: that.data.bmrData[0],
          recordTime: that.data.bmrTime[0],
          recordTitle: '基础代谢'
        })
        break;
      case 8:
        //蛋白质率
        that.getBarGraphData(that.data.proteinData,that.data.proteinTime)
        that.getLineGraphData(that.data.proteinData,that.data.proteinTime)
        that.setData({
          recordData: that.data.proteinData[0],
          recordTime: that.data.proteinTime[0],
          recordTitle: '蛋白质率'
        })
        break;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    // this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    Chart = null
    LineChart = null
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    Chart = null
    LineChart = null
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: 'PAPN小程序',
      path: 'pages/index/index?puid=' + app.globalData.userId,
      success: function(res) {
          res.shareTickets 
      },
      fail: function(res) {
          console.log(res)
      }
    }
  }
})